local hx__peibanbanyi = fk.CreateSkill {
  name = "hx__peibanbanyi",
}

hx__peibanbanyi:addEffect(fk.EventPhaseStart, {
  anim_type = "special",
  can_trigger = function(self, event, target, player, data)
    return target ~= player and player:hasSkill(hx__peibanbanyi.name) and target.phase == Player.Start
  end,
  on_cost = function(self, event, target, player, data)
    return player.room:askToSkillInvoke(player, { skill_name = hx__peibanbanyi.name, 
    prompt = "#hx__peibanbanyi-invoke::"..target.id,
  })
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    player:turnOver()
    local choice = room:askToChoice(target,{
      choices = {"hx__peibanbanyi-give::" .. player.id,"hx__peibanbanyi-discard"},
      cancelable = false,
      skill_name = hx__peibanbanyi.name,
    })
    if choice == "hx__peibanbanyi-discard" then
      target:throwAllCards("hand")
    else
      if not player:isNude() then
        local card = room:askToChooseCard(target, {
          skill_name = hx__peibanbanyi.name,
          target = player,
          flag = "he",
        })
        room:obtainCard(target, card, false, fk.ReasonPrey, target, hx__peibanbanyi.name)
      end
      if #target:getCardIds("h") > 0 then
        local card = room:askToChooseCard(player, {
          skill_name = hx__peibanbanyi.name,
          target = target,
          flag = "h",
          prompt = "请选择要获得的第一张牌（共两张）",
        })
        room:obtainCard(player, card, false, fk.ReasonPrey, player, hx__peibanbanyi.name)
        if #target:getCardIds("h") == 0 then return end
        local card2 = room:askToChooseCard(player, {
          skill_name = hx__peibanbanyi.name,
          target = target,
          flag = "h",
          prompt = "请选择要获得的第二张牌（共两张）",
        })
        room:obtainCard(player, card2, false, fk.ReasonPrey, player, hx__peibanbanyi.name)
      end
    end
  end,
})


return hx__peibanbanyi
